`
https://leetcode.cn/problems/interval-list-intersections/
`

/**
 * @param {number[][]} firstList
 * @param {number[][]} secondList
 * @return {number[][]}
 */
var intervalIntersection = function (firstList, secondList) {
  // 双指针
  let i = 0; j = 0
  const res = []

  while (i < firstList.length && j < secondList.length) {
    const a1 = firstList[i][0], a2 = firstList[i][1]
    const b1 = secondList[j][0], b2 = secondList[j][1]

    // 两个区间存在交集
    if (b2 >= a1 && a2 >= b1) {
      res.push([Math.max(a1, b1), Math.min(a2, b2)])
    }

    // // 指针前进
    if (b2 < a2) {
      j++;
    } else {
      i++;
    }
  }

  return res
};